﻿using System;
using FluentlyXml.Core.Deserialization;
using FluentlyXml.Core.DSL;
using FluentlyXml.Core.Serialization;

namespace FluentlyXml.Core
{
	/// <summary>
	/// Creates serializers based on current configuration settings. 
	/// </summary>
	public class FluentSerializerFactory
	{
		private readonly RuntimeSerializationConfig _runtimeConfig;

		public FluentSerializerFactory(Action<FluentSerializationSpec> configAction)
		{
			var config = new FluentSerializationSpec();

			configAction(config);

			_runtimeConfig = config.GetConfig().Compile();
		}

		/// <summary>
		/// Creates a new serializer with a new scope.
		/// </summary>
		/// <returns></returns>
		public IFluentSerializer CreateSerializer()
		{
			return new FluentSerializer(_runtimeConfig);
		}

		public IFluentDeserializer CreateDeserializer()
		{
			return new FluentDeserializer(_runtimeConfig);
		}
	}
}